function start() {
  var startAddress = '111 8th Ave, NYC';
  var finishAddress = '364 W. 18th, NYC';

  racecar = new Car;
  keys = new Keys;
  course = new Course;
  course.setStart(startAddress);
  course.setFinish(finishAddress);
  finishCoord = course.getFinishCoord();
}

function everyFrame() {
  handleKeys();
  detectCollisions();
  //  racecarCoord = racecar.getCoord();
}

function detectCollisions() {
  if (AlmostEquals(racecarCoord.lat(),
                   finishCoord.lat()) &&
      AlmostEquals(racecarCoord.lng(),
                   finishCoord.lng())) {
    alert('Finished!');
  }
}

function AlmostEquals(a, b) {
   if (Math.abs(a - b) < 0.0001) {
     return true;
   }
   return false;
}


function handleKeys() {
  if (keys.upIsPressed()) {
    racecar.accelerate();
  } else if (keys.downIsPressed()) {
    racecar.decelerate();
  }
  if (keys.leftIsPressed()) {
    racecar.turnLeft();
  } else if (keys.rightIsPressed()) {
    racecar.turnRight();
  }
}
